package com.linkage.jz.bankruptcy.adapter.Vote;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.bean.Vote.ProVoteVoters;
import com.linkage.seapeak.utils.CommonUtils;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * 表决人员列表--不带分组的adapter
 */
public class ProVoteVotersNoGroupsAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<ProVoteVoters> mData;

    public ProVoteVotersNoGroupsAdapter(Context context, List<ProVoteVoters> mData) {
        this.context = context;
        this.mData = mData;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_pro_vote_voters_no_group, parent, false);
        /*RecyclerView.ViewHolder holder = null;
        switch (viewType) {
            case HEADER:
                if(headerView != null)
                    holder = new ViewHolderNormal(headerView);
                break;
            case NORMAL:
                view = LayoutInflater.from(context).inflate(R.layout.adapter_find_expert_item, parent, false);
                holder = new ViewHolderNormal(view);
                break;
        }*/
        RecyclerView.ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        final ProVoteVoters item = mData.get(position);
        ViewHolder holder = (ViewHolder) viewHolder;
       /* Glide.with(context).load(holder.avatar)
                .placeholder(R.drawable.avatar_defult)//图片加载出来前，显示的图片
                .error(R.drawable.avatar_defult)//图片加载失败后，显示的图片
                .centerCrop().into(holder.avatar);*/
        holder.name.setText(item.getName());
        holder.sureMoney.setText("确认金额：" + CommonUtils.resetMoney(item.getSureMoney()) + "元");
        holder.voteMoney.setText("表决金额：" + CommonUtils.resetMoney(item.getVoteMoney()) + "元");
        holder.voteCode.setText("参会编号：" + item.getId());
        holder.btnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "删除了" + item.getName() + "", Toast.LENGTH_SHORT).show();
            }
        });

//        Glide.with(context).load(item.getAvatar())
//                .bitmapTransform(new CropCircleTransformation(context))
//                .placeholder(R.drawable.logo)
//                .into(holder.avatar);
        ImageView imageview = holder.avatar;
        Glide.with(context).load(item.getAvatar())
                .bitmapTransform(new CropCircleTransformation(context))
                .placeholder(R.drawable.logo)
                .into(imageview);
    }

    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private CircleImageView avatar;
        private TextView name;
        private TextView sureMoney;
        private TextView voteMoney;
        private TextView changeBtn;
        private TextView voteCode;
        private Button btnDelete;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            avatar = itemView.findViewById(R.id.voter_avatar);
            name = itemView.findViewById(R.id.voter_name);
            sureMoney = itemView.findViewById(R.id.voter_sure_money);
            voteMoney = itemView.findViewById(R.id.voter_vote_money);
            changeBtn = itemView.findViewById(R.id.voter_change);
            voteCode = itemView.findViewById(R.id.voter_code);
            btnDelete = itemView.findViewById(R.id.btnDelete);
        }
    }
}
